<?php
class IndexAction extends GlobalAction{
    public function index(){
    	$a = M('info');
    	$this->GlobalName();
    	$this->menu();
		$this->display();
		
    }
    public function main(){    	
    	$this->GlobalName();
		$this->display();
    }
    public function menu_list(){
    	$menu = M('menu');
    	$menu_top = $menu->where("meid = '' and bottom = '0'")->order('sorting asc,menu_id asc')->findall();
    	$menu_top1 = $menu->where("meid != '' and bottom = '0'")->order('sorting asc,menu_id asc')->findall();
    	$menu_bottom = $menu->where("bottom = '1'")->order('sorting asc,menu_id asc')->findall();
    	$this->assign('menu_top',$menu_top);
    	$this->assign('menu2',$menu_top1);
    	$this->assign('menu_bottom',$menu_bottom);
    	$this->GlobalName();
		$this->display();
    }
    public function menu_add(){
    	$menu = M('menu');
    	$menu1 = $menu->where("meid = '' and bottom = '0'")->order('sorting asc,menu_id asc')->findall();
    	$menu2 = $menu->where("meid != '' and bottom = '0'")->order('sorting asc,menu_id asc')->findall();
    	$this->assign('menu1',$menu1);
    	$this->assign('menu2',$menu2);
    	$this->GlobalName();
		$this->display();
    }
    public function menu_news_get(){
    	$menu = M('menu');
    	$menu->create();
    	if ($menu->add()) {
    		$this->get_alert('新增成功');
    	};
    }
    public function menu_edit(){
    	$menuid = $_GET['menuid'];
    	$menu = M('menu');
    	$menu1 = $menu->where("meid = '' and bottom = '0'")->order('sorting asc,menu_id asc')->findall();
    	$menu2 = $menu->where("meid != '' and bottom = '0'")->order('sorting asc,menu_id asc')->findall();
    	$this->assign('menu1',$menu1);
    	$this->assign('menu2',$menu2);
    	$menu = $menu->where('menu_id = '.$menuid)->findall();
    	$this->assign('menu',$menu);
    	$this->GlobalName();
		$this->display();
    }
    public function menu_edit_get(){
    	$menu = M('menu');
    	$menu->create();
    	if ($menu->save()) {
    		$this->get_alert('修改成功');
    	};
    }
    public function menu_delete(){
    	$menu = M('menu');
    	$del = $_POST['del'];
    	$delete = $del[0];
    	for ($i=1;$i < count($del);$i++){
    		$delete = $delete.','.$del[$i];
    	}
    	if ($menu->delete($delete)) {
    		$this->get_alert('删除成功');
    	};
    }
     public function link_list(){
     	$link = M('link');
     	$link_list = $link->order('sorting asc,link_id asc')->findall();
    	$this->assign('link',$link_list);
    	$this->GlobalName();
		$this->display();
     }
         public function link_add(){
    	$this->GlobalName();
		$this->display();
    }
    public function link_news_get(){
    	$menu = M('link');
    	$menu->create();
    	if ($menu->add()) {
    		$this->get_alert('新增成功');
    	};
    }
    public function link_edit(){
    	$linkid = $_GET['pid'];
    	$link = M('link');
    	$link = $link->where('link_id = '.$linkid)->findall();
    	$this->assign('link',$link);
    	$this->GlobalName();
		$this->display();
    }
    public function link_edit_get(){
    	$menu = M('link');
    	$menu->create();
    	if ($menu->save()) {
    		$this->get_alert('修改成功');
    	};
    }
    public function link_delete(){
    	$menu = M('link');
    	$del = $_POST['del'];
    	$delete = $del[0];
    	for ($i=1;$i < count($del);$i++){
    		$delete = $delete.','.$del[$i];
    	}
    	if ($menu->delete($delete)) {
    		$this->get_alert('删除成功');
    	};
    }
    
    public function system(){
    	$system = M('system');
    	$system = $system->findall();
    	$this->assign('system',$system);
    	$this->GlobalName();
		$this->display();
    }
	public function del_admin_cache(){
		header("Content-type: text/html; charset=utf-8");
		$dirName = "admin/Runtime/Cache";
       	$this->del_dir($dirName);
		$dirName = "admin/Runtime/Data/_fields";
       	$this->del_dir($dirName);
		
    }

	public function del_web_cache(){
		header("Content-type: text/html; charset=utf-8"); 
		$dirName = "compdd/Runtime/Cache";
       	$this->del_dir($dirName);
		$dirName = "compdd/Runtime/Data/_fields";
       	$this->del_dir($dirName);
    }
    public function system_get(){

		$system = M('system');
    	if (!empty($_FILES['logo_up']['name'])) {
    		$_POST['logo'] = $this->_upload('0');
    	}
    	$system->create();
    	if ($system->save()) {
    		$this->get_alert('修改成功');
    	};
    }
    
    public function ajax_link_show(){
    	$this->ajax_get('link','show_m');
    }
    public function ajax_menu_show(){
    	$this->ajax_get('menu','show_m');
    }
    
    public function left(){//默认左列表
    	$left = array(
    		array('sort'=>'Index','name'=>'系统设置','value'=>'system'),
    		array('sort'=>'Index','name'=>'导航管理','value'=>'menu_list'),
    		array('sort'=>'Index','name'=>'新增导航','value'=>'menu_add'),
    		array('sort'=>'Index','name'=>'友情连接','value'=>'link_list'),
    		array('sort'=>'Index','name'=>'新增友情连接','value'=>'link_add'),
    		array('sort'=>'Feedback','name'=>'留言管理','value'=>'feedback_list'),
    		array('sort'=>'Index','name'=>'清除前台缓存','value'=>'del_web_cache'),
    		array('sort'=>'Index','name'=>'清除后台缓存','value'=>'del_admin_cache')
    	);
     	$this->assign('user',$_SESSION['User']);
    	$this->assign('left',$left);
    	$this->display();
    }
    private function menu(){//后台系统目录
    	$menu = array(
    		array('name'=>'信息管理','value'=>'Proflie'),
    		array('name'=>'产品管理','value'=>'Product'),
    		array('name'=>'频道管理','value'=>'Part'),
    		array('name'=>'招聘管理','value'=>'Job'),
    		array('name'=>'会员管理','value'=>'Member')
    	);
    	$this->assign('menu',$menu);
    }
    
}
?>